//
//  MineHelpCenterViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/4/2.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "MineHelpCenterViewController.h"
#import "MineHelpCenterTableViewCell.h"

#import "MineHelpCenterDetailViewController.h"

#import "MineHelpCenterModelPack.h"


@interface MineHelpCenterViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *mineHelpCenterModelArray;

@end

@implementation MineHelpCenterViewController

-(NSMutableArray *)mineHelpCenterModelArray
{
    if (_mineHelpCenterModelArray == nil) {
        _mineHelpCenterModelArray = [NSMutableArray array];
    }
    return _mineHelpCenterModelArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"帮助中心";
    self.view.backgroundColor = ETColorWithRGB(242, 244, 246);
    [self createTableView];
    
    //请求帮助列表
    [self getHelpCenterList];
    
}
-(void)getHelpCenterList
{
    MineHelpCenterRequest *request = [[MineHelpCenterRequest alloc] init];
    request.type = @"2";
    request.pageNum = @"1";
    request.pageSize = @"500";
    request.keyword = @"";
    NSDictionary *dic = [request mj_keyValues];
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/help/helpListF0200"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:dic HttpBody:nil SuccessHandler:^(id responseObject) {
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealHelpCenterList:responseObject];
        }
        
    } FailedHandler:^(NSError *error) {
        
    }];
}
-(void)dealHelpCenterList:(id)responseObject
{
    MineHelpCenterResponse *mineHelpCenterResponse = [MineHelpCenterResponse mj_objectWithKeyValues:responseObject];
    for (MineHelpCenterRecord *record in mineHelpCenterResponse.response.list) {
        [self.mineHelpCenterModelArray addObject:record];
    }
    [self.tableView reloadData];
}

-(void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, self.view.frame.size.width, ETScreenH - 64) style:(UITableViewStyleGrouped)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:244 / 255.0 blue:246 / 255.0 alpha:1];
    //    self.tableView.scrollEnabled = NO;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[MineHelpCenterTableViewCell class] forCellReuseIdentifier:@"cell"];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mineHelpCenterModelArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 54;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineHelpCenterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    MineHelpCenterRecord *record = self.mineHelpCenterModelArray[indexPath.row];
    cell.tipsLab.text = record.conTitle;
    //点击不变色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == self.mineHelpCenterModelArray.count - 1) {
        cell.lineView.hidden = YES;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineHelpCenterRecord *record = self.mineHelpCenterModelArray[indexPath.row];
    MineHelpCenterDetailViewController *mineDetailVC = [[MineHelpCenterDetailViewController alloc] init];
    mineDetailVC.conTitle = record.conTitle;
    mineDetailVC.content = record.content;
    [self.navigationController pushViewController:mineDetailVC animated:YES];
}


@end
